<template>
  <view>
    <nav-bar title="基本信息"></nav-bar>
    <view class="basicInfo-form"> 
      <scroll-view scroll-y :style="{ height: formHeight }">
        <view class="form-box">
          <view class="form-top">
           <view class="form-title">请添加病情描述</view>
           <view class="form-word">认真填写完善以下信息,以便对您的病情更加了解</view>
          </view>
          <you-form
            v-if="showForm"
            ref="form"
            :showFormTitle="false"
            :formConfig="basicConfig"
            v-model="basicData"
          ></you-form>
        </view>
      </scroll-view>
      <you-bottom-btn
        v-if="hasInfo !== '1'"
        :btnConfig="bottomBtnConfig"
        @clickSubmit="clickSubmit"
        @clickCancel="clickCancel"
      ></you-bottom-btn>
    </view>
  </view>
</template>

<script>
  import api_user from '@/api/user'
  import { BASIC_FORM } from './formConfig/basicConfig'
  export default {
    name: 'BasicInfo',
    data() {
      return {
        formHeight: '',
        basicConfig: [],
        basicData: {},
        bottomBtnConfig: [
          { text: '提交', class: 'confirm', funcName: 'clickSubmit' }
        ],
        memberCardId: null,
        hasInfo: '',
        showForm: false,
        orderNum: null
      }
    },
    onLoad(options) {
      this.formHeight = this.$store.getters.heightData.noTabMainHeight - 85 + 'px'
      this.basicConfig = uni.$u.deepClone(BASIC_FORM)
      if(options.cardId){
        this.memberCardId = Number(options.cardId)
      }else{
        this.memberCardId = null
      }
      if (options.hasInfo && options.hasInfo === '1') {
        this.formHeight = this.$store.getters.heightData.noTabMainHeight - 10 + 'px'
        this.hasInfo = options.hasInfo
        this.getBasicInfo()
        this.basicConfig.forEach(item => {
          item.isDisabled = true
        })
      } else {
        this.showForm = true
      }
      if (options.orderNum) {
        this.orderNum = options.orderNum
      }
    },
    methods: {
      getBasicInfo() {
        const params = {
          memberCardId: this.memberCardId
        }
        api_user.fetchCaseDetail(params).then(res => {
          if (res.code !== 200) return
          this.basicData = res.data
          const result = res.data
          result.bodySignFaceImg && result.bodySignFaceImg.includes('http') ? result.bodySignFaceImg : this.baseUrl + result.bodySignFaceImg,
          result.bodySignBackImg && result.bodySignBackImg.includes('http') ? result.bodySignBackImg : this.baseUrl + result.bodySignBackImg,
          result.bodySignSideImg && result.bodySignSideImg.includes('http') ? result.bodySignSideImg : this.baseUrl + result.bodySignSideImg
          this.showForm = true
        })
      },
      async clickSubmit() {
        const formCheck = await this.$refs.form.checkFormData()
        if (!formCheck) return uni.$u.toast('请将表单数据填写完整')
        const params = {
          ...this.basicData,
          memberCardId: this.memberCardId,
          orderNum: this.orderNum
        }
        api_user.addCase(params).then(res => {
          if (res.code !== 200) return
          uni.redirectTo({ url: '/subPages/userMine/memberBenefits/customServeList' })
        })
      }
    }
  }
</script>
<style lang="scss" scoped>
  .basicInfo-form {
    padding-top: 15px;
  }
  .form-box {
    margin: 0 30rpx;
    border-radius: 16rpx;
    background-color: #FFF;
    overflow: hidden;
    .form-top{
      padding: 30rpx 0 0 30rpx;
      .form-title{
        font-size: 36rpx;
        font-weight: 600;
        color: #000;
      }
      .form-word{
        margin: 10rpx 0 30rpx;
        font-size: 24rpx;
        color: #999;
      }
    }
  }
</style>
